<?php

namespace Admin\Service;

class PublicService
{
    public static function upload($file)
    {
        $config = [
            'maxSize'    =>    3145728,
            'rootPath'   =>    './Uploads/',
            'savePath'   =>    '',
            'saveName'   =>    array('uniqid',''),
            'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),
            'autoSub'    =>    true,
            'subName'    =>    array('date','Ymd'),
        ];

        $upload = new \Think\Upload($config); //实例化上传类

        $info = $upload->uploadOne($file);

        if (!$info) {
            return ['code' => false, 'msg' => $upload->getError());
        } else {
            return ['code' => true, 'file' => $info['savepath'] . $info['savename']];
        }
    }
}